<?php

namespace app\common\model;

use think\Model;

/**
 * 分销订单数据记录模型
 */
class Distribution extends Model
{

    // 表名
    protected $name = 'distribution';
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = '';
    // 追加属性
    protected $append = [
        'identity_text',
    ];


    public function getIdentityList()
    {
        return ['0' => __('Identity 0'), '1' => __('Identity 1'), '2' => __('Identity 2')];
    }
    public function getIdentityTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['identity']) ? $data['identity'] : '');
        $list = $this->getIdentityList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getStatusList()
    {
        return ['0' => __('Distribution.status 0'), '1' => __('Distribution.status 1'), '2' => __('Distribution.status 2')];
    }

    public function ordergoods()
    {
        return $this->belongsTo('app\index\model\wanlshop\OrderGoods', 'order_goods_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function level()
    {
        return $this->belongsTo('app\common\model\user\LevelOrder', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function order()
    {
        return $this->belongsTo('app\admin\model\wanlshop\Order', 'order_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function payuser()
    {
        return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
    public function commissuser()
    {
        return $this->belongsTo('app\common\model\User', 'commiss_user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
